import requests
from common.config import *
from tests.rypark_background.get_cookie import *


class Login:
    # 用户登录
    def user_login(self, env, user, pw):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/login"
        header = {"content-type": "application/json;charset=UTF-8"}
        dict = {"account": user, "password": pw}
        return requests.post(url, headers=header, json=dict).json()

    # 获取用户信息
    def user_info(self, cookie, env):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/getUserInfo"
        header = {"content-type": "application/json;charset=UTF-8",
                  "cookie": cookie}
        return requests.get(url, headers=header).json()

    # 用户登出
    def user_logout(self, cookie, env):
        base_url = getconf(env, "rypark_url")
        url = base_url + "easypark-backend/parkUser/logout"
        header = {"content-type": "application/json;charset=UTF-8",
                  "cookie": cookie}
        return requests.get(url, headers=header).json()
